package com.zlm.common.dto;

import org.apache.commons.lang3.Range;

import java.io.Serializable;

/**
 * 坐标实体类
 * @author xhj
 */
public class CoordinatesDto implements Serializable {

    private static final long serialVersionUID = 4251853597371339954L;
    private static final Range<Double> LATITUDE_RANGE = Range.between(-90.0, 90.0);
    private static final Range<Double> LONGITUDE_RANGE = Range.between(-180.0, 180.0);

    /**
     * 经度
     */
    private Double longitude;

    /**
     * 纬度
     */
    private Double latitude;

    public CoordinatesDto(Double longitude, Double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }


    public boolean isValid() {
        return latitude != null && longitude != null && LATITUDE_RANGE.contains(latitude) && LONGITUDE_RANGE.contains(longitude);
    }

    public String toWKT() {
        return String.format("%f,%f", latitude, longitude);
    }
}
